<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>对象转固定格式</title>
  </head>
  <body>
    <script>
      const obj = [{ 姓名: "青秀山", 牛肉03: "0", 鸡肉002: "15" }]

      function dataConvert(data) {
        let result = []
        for (let item of data) {
          closure(item)
        }
        function closure(obj) {
          const name = ["姓名"]
          delete obj["姓名"]
          for (let key in obj) {
            const newItem = {
              name,
              title: key,
              num: obj[key],
            }
            result.push(newItem)
          }
        }
        return result
      }
      console.log(dataConvert(obj))
    </script>
  </body>
</html>
